﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace PreContractWeb
{
    [Serializable]
    public struct SortManager
    {
        private string _sortColumn;
        private string _sortDirection;

        public void DoSort(string column, string direction)
        {
            _sortColumn = column;
            _sortDirection = direction;

        }

        public bool CheckSortColumnExist(string column)
        {
            column = column.Trim();

            if (_sortColumn != null && _sortColumn.Equals(column))
            {
                return true;
            }
            else
            {
                return false;
            }


        }


        public string DoSort(string column)
        {
            column = column.Trim();
            if (column == String.Empty) return String.Empty;

            if (_sortColumn != null && _sortColumn.Equals(column))
            {
                if (_sortDirection == "DESC") _sortDirection = "ASC";
                else _sortDirection = "DESC";
            }
            else
            {
                _sortColumn = column;
                _sortDirection = "ASC";
            }

            return _sortColumn + " " + _sortDirection;
        }

        public override string ToString()
        {
            if (_sortColumn == null)
                return string.Empty;

            return _sortColumn + " " + _sortDirection;
        }
    }
}
